import 'dart:io';

import 'package:bruno/bruno.dart';
import 'package:flutter/cupertino.dart';
import 'package:flutter/material.dart';
import 'package:get/get.dart';
import 'package:getwidget/getwidget.dart';
import 'package:images_picker/images_picker.dart';
import 'package:meal/constant/sizes.dart';
import 'package:meal/route/route.dart';
import 'package:meal/ui/action_card_title.dart';
import 'package:meal/utils/colors.dart';
import 'package:meal/utils/styles.dart';
import 'package:meal/utils/tools.dart';

///
/// 店铺详情
///
class StoreInfo extends StatefulWidget {
  const StoreInfo({Key? key}) : super(key: key);

  @override
  State<StoreInfo> createState() => _StoreInfoState();
}

class _StoreInfoState extends State<StoreInfo> {
  String path = '';

  BrnCardTitleConfig get brnCardTitleConfig {
    return BrnCardTitleConfig(
        cardTitlePadding: EdgeInsets.zero,
        titleWithHeightTextStyle: BrnTextStyle(
            color: ColorsUtils.parseColorFromHexString(ColorsUtils.color000),
            fontSize: Sizes.default15,
            fontWeight: FontWeight.normal),
        titleTextStyle: BrnTextStyle(
            color: ColorsUtils.parseColorFromHexString(ColorsUtils.color000),
            fontSize: Sizes.default15,
            fontWeight: FontWeight.normal),
        accessoryTextStyle: BrnTextStyle(
            color: ColorsUtils.parseColorFromHexString(ColorsUtils.color797),
            fontSize: Sizes.default14,
            fontWeight: FontWeight.normal));
  }

  @override
  Widget build(BuildContext context) {
    return Scaffold(
      backgroundColor: ToolsUtils.getDefaultBackgroundColor(),
      appBar: ToolsUtils.getDefaultBrnAppBar('店铺详情'),
      body: SingleChildScrollView(
        physics: const BouncingScrollPhysics(),
        child: Column(
          children: [
            Container(
              padding: const EdgeInsets.symmetric(horizontal: Sizes.default15),
              alignment: Alignment.centerLeft,
              height: Sizes.default50,
              child: Text(
                '账号信息',
                style: StylesUtils.customTextStyle(
                    fontSize: Sizes.default13, color: ColorsUtils.color797),
              ),
            ),
            Container(
              decoration: const BoxDecoration(color: Colors.white),
              padding: const EdgeInsets.symmetric(
                  vertical: Sizes.default10, horizontal: Sizes.default20),
              child: Column(
                children: [
                  ActionCardTitle(
                    title: '店铺LOGO',
                    subTitleWidget: Container(
                        constraints: const BoxConstraints.tightFor(
                            width: Sizes.default40, height: Sizes.default20),
                        alignment: Alignment.center,
                        decoration: BoxDecoration(
                            borderRadius: const BorderRadius.all(Radius.circular(Sizes.default3)),
                            border: Border.all(color: ColorsUtils.rgba(204, 0, 0, 1))),
                        child: Text(
                          '审核中',
                          style: StylesUtils.customTextStyle(
                              color: ColorsUtils.colorCc0, fontSize: Sizes.default12),
                        )),
                    accessoryWidget: ClipOval(
                        child: path.isNotEmpty
                            ? GFImageOverlay(
                                image: FileImage(File(path)),
                                width: Sizes.default60,
                                height: Sizes.default60)
                            : ToolsUtils.getAssetImage('shop_header.png',
                                width: Sizes.default60, height: Sizes.default60)),
                    themeData: brnCardTitleConfig,
                    onTap: showActionSheet,
                  ),
                  Container(
                    padding: const EdgeInsets.symmetric(vertical: Sizes.default15),
                    child: ActionCardTitle(
                      title: '店铺名称',
                      subTitleWidget: Container(
                          constraints: const BoxConstraints.tightFor(
                              width: Sizes.default40, height: Sizes.default20),
                          alignment: Alignment.center,
                          decoration: BoxDecoration(
                              borderRadius: const BorderRadius.all(Radius.circular(Sizes.default3)),
                              border: Border.all(color: ColorsUtils.rgba(204, 0, 0, 1))),
                          child: Text(
                            '审核中',
                            style: StylesUtils.customTextStyle(
                                color: ColorsUtils.colorCc0, fontSize: Sizes.default12),
                          )),
                      accessoryWidget: Text('默林如斯广东粉肠早餐店(凤凰广场店)',
                          style: StylesUtils.customTextStyle(color: ColorsUtils.color797)),
                      themeData: brnCardTitleConfig,
                      onTap: () {
                        Get.toNamed(RouteGet.userStoreEdit);
                      },
                    ),
                  ),
                  ActionCardTitle(
                    title: '登录账号',
                    accessoryWidget: Text('+86 135897517',
                        style: StylesUtils.customTextStyle(color: ColorsUtils.color797)),
                    themeData: brnCardTitleConfig,
                    onTap: () {
                      Get.toNamed(RouteGet.userMobileUnbind);
                    },
                  ),
                ],
              ),
            ),
            Container(
              padding: const EdgeInsets.symmetric(horizontal: Sizes.default15),
              alignment: Alignment.centerLeft,
              height: Sizes.default50,
              child: Text(
                '联系方式',
                style: StylesUtils.customTextStyle(
                    fontSize: Sizes.default13, color: ColorsUtils.color797),
              ),
            ),
            Container(
              decoration: const BoxDecoration(color: Colors.white),
              padding: const EdgeInsets.symmetric(
                  vertical: Sizes.default10, horizontal: Sizes.default20),
              child: Column(
                children: [
                  BrnCommonCardTitle(
                    title: '负责人',
                    accessoryText: '张店长',
                    themeData: brnCardTitleConfig,
                  ),
                  Container(
                    padding: const EdgeInsets.symmetric(vertical: Sizes.default15),
                    child: BrnCommonCardTitle(
                      title: '联系方式',
                      accessoryText: '+86 1385518607',
                      themeData: brnCardTitleConfig,
                    ),
                  ),
                  BrnCommonCardTitle(
                    title: '接单电话',
                    accessoryText: '+86 1385518607',
                    themeData: brnCardTitleConfig,
                  ),
                  Container(
                    padding: const EdgeInsets.symmetric(vertical: Sizes.default15),
                    child: BrnCommonCardTitle(
                      title: '店铺地址',
                      accessoryText: '广西省北海市海城区北部湾广场西侧',
                      themeData: brnCardTitleConfig,
                    ),
                  ),
                  BrnCommonCardTitle(
                    title: '店铺坐标',
                    accessoryText: '查看地图',
                    themeData: brnCardTitleConfig,
                  ),
                ],
              ),
            ),
            Container(
              padding: const EdgeInsets.symmetric(horizontal: Sizes.default15),
              alignment: Alignment.centerLeft,
              height: Sizes.default50,
              child: Text(
                '商家信息',
                style: StylesUtils.customTextStyle(
                    fontSize: Sizes.default13, color: ColorsUtils.color797),
              ),
            ),
            Container(
              decoration: const BoxDecoration(color: Colors.white),
              padding: const EdgeInsets.symmetric(
                  vertical: Sizes.default10, horizontal: Sizes.default20),
              child: Column(
                children: [
                  BrnCommonCardTitle(
                    title: '店铺类型',
                    accessoryText: '餐饮店铺',
                    themeData: brnCardTitleConfig,
                  ),
                  Container(
                    padding: const EdgeInsets.symmetric(vertical: Sizes.default15),
                    child: ActionCardTitle(
                      title: '店铺名称',
                      subTitleWidget: Container(
                          constraints: const BoxConstraints.tightFor(
                              width: Sizes.default40, height: Sizes.default20),
                          alignment: Alignment.center,
                          decoration: BoxDecoration(
                              borderRadius: const BorderRadius.all(Radius.circular(Sizes.default3)),
                              border: Border.all(color: ColorsUtils.rgba(204, 0, 0, 1))),
                          child: Text(
                            '审核中',
                            style: StylesUtils.customTextStyle(
                                color: ColorsUtils.colorCc0, fontSize: Sizes.default12),
                          )),
                      accessoryWidget: Text('肠粉/其他饮品',
                          style: StylesUtils.customTextStyle(color: ColorsUtils.color797)),
                      themeData: brnCardTitleConfig,
                      onTap: () {
                        Get.toNamed(RouteGet.categoryBreed);
                      },
                    ),
                  ),
                  BrnCommonCardTitle(
                    title: '保证金',
                    accessoryText: '￥8600',
                    themeData: brnCardTitleConfig,
                  ),
                  Container(
                    padding: const EdgeInsets.symmetric(vertical: Sizes.default15),
                    child: BrnCommonCardTitle(
                      title: '保证金状态',
                      accessoryText: '已缴存',
                      themeData: brnCardTitleConfig,
                    ),
                  ),
                  BrnCommonCardTitle(
                    title: '配送方式',
                    accessoryText: '平台配送',
                    themeData: brnCardTitleConfig,
                  ),
                  Container(
                    padding: const EdgeInsets.only(top: Sizes.default15),
                    child: BrnCommonCardTitle(
                      title: '开店日期',
                      accessoryText: '2023-02-10',
                      themeData: brnCardTitleConfig,
                    ),
                  )
                ],
              ),
            ),
          ],
        ),
      ),
    );
  }

  void showActionSheet() async {
    ToolsUtils.openCupertinoModalPopup(context, setMediaImg, setMediaImg);
  }

  void setMediaImg(List<Media> res) {
    setState(() {
      path = res[0].path;
    });
  }
}
